﻿@using System.Diagnostics
@using Masuit.MyBlogs.Core.Common
@using Masuit.MyBlogs.Core.Models.DTO
@using Masuit.MyBlogs.Core.Models.Entity
@using Masuit.MyBlogs.Core.Models.ViewModel
@using Masuit.Tools.Core.Net
@using Microsoft.AspNetCore.Http
@model Masuit.MyBlogs.Core.Models.ViewModel.HomePageViewModel
@{
    ViewBag.Title = "首页";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<FastShare> shares = ViewBag.FastShare;
    Context.Request.Path = new PathString("/posts");
}
<link href="~/Assets/banner/bootstrap-touch-slider.css" rel="stylesheet" />
@if (Model.Banner.Any())
{
    <div id="bootstrap-touch-slider" class="carousel bs-slider fade  control-round indicators-line" data-ride="carousel" data-pause="hover" data-interval="5000" id="@Stopwatch.GetTimestamp()">
        <ol class="carousel-indicators">
            @for (int i = 0; i < Model.Banner.Count; i++)
            {
                if (i == 0)
                {
                    <li data-target="#bootstrap-touch-slider" data-slide-to="@i" class="active"></li>
                }
                else
                {
                    <li data-target="#bootstrap-touch-slider" data-slide-to="@i"></li>
                }
            }
        </ol>
        <div class="carousel-inner" role="listbox" id="@Stopwatch.GetTimestamp()">
            @for (int i = 0; i < Model.Banner.Count; i++)
            {
                var p = Model.Banner[i];
                string[] ani = { "zoomInRight", "flipInX", "fadeInLeft", "lightSpeedIn", "fadeInUp", "zoomInLeft", "fadeInRight" };
                Random r = new Random();
                <div class="item @(i == 0 ? "active" : "")" class="img-responsive" id="@Stopwatch.GetTimestamp()">
                    <a asp-controller="Advertisement" asp-action="Redirect" asp-route-id="@p.Id" target="_blank" data-animation="animated @ani[r.Next(ani.Length)]">
                        <img src="@p.ImageUrl" title="@p.Title" alt="@p.Description" />
                    </a>
                </div>
            }
        </div>
        <a class="left carousel-control" href="#bootstrap-touch-slider" role="button" data-slide="prev">
            <span class="fa fa-angle-left" aria-hidden="true"></span>
            <span class="sr-only">上一个</span>
        </a>
        <a class="right carousel-control" href="#bootstrap-touch-slider" role="button" data-slide="next">
            <span class="fa fa-angle-right" aria-hidden="true"></span>
            <span class="sr-only">下一个</span>
        </a>
    </div>
}
<br />
<script src="https://cdn.staticfile.org/jquery.touchswipe/1.6.19/jquery.touchSwipe.min.js"></script>
<script src="~/Assets/banner/bootstrap-touch-slider.min.js"></script>
@if (Model.Notices.Any())
{
    <div class="container notice">
        <a asp-controller="Notice" asp-action="Details" asp-route-id="@(Model.Notices.FirstOrDefault()?.Id)">
            <h3 class="size18 text-red text-center">网站最新公告</h3>
        </a>
        @Html.Raw(Model.Notices[0].Content.Replace("img src=", $"img title='{CommonHelper.SystemSettings["Title"]}' alt='{CommonHelper.SystemSettings["Title"]}' data-original="))
    </div>
}
@if (shares.Any())
{
    <div class="container padding-clear">
        <div class="panel panel-info">
            <div class="panel-heading">⚡小撇步Tips⚡</div>
            <div class="panel-body padding-clear">
                <table class="table table-bordered margin-clear">
                    @for (int i = 1; i < shares.Count + 1; i += 2)
                    {
                        if (i < shares.Count)
                        {
                            <tr>
                                @if (string.IsNullOrEmpty(shares[i - 1].Link))
                                {
                                    <td style="width: 50%">▸ @shares[i - 1].Title</td>
                                }
                                else
                                {
                                    <td style="width: 50%">▸ <a href="@shares[i - 1].Link" target="_blank">@shares[i - 1].Title</a></td>
                                }
                                @if (string.IsNullOrEmpty(shares[i].Link))
                                {
                                    <td style="width: 50%">▸ @shares[i].Title</td>
                                }
                                else
                                {
                                    <td style="width: 50%">▸ <a href="@shares[i].Link" target="_blank">@shares[i].Title</a></td>
                                }
                            </tr>
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(shares[i - 1].Link))
                            {
                                <tr>
                                    <td colspan="2">▸ @shares[i - 1].Title</td>
                                </tr>
                            }
                            else
                            {
                                <tr>
                                    <td colspan="2">▸ <a href="@shares[i - 1].Link" target="_blank">@shares[i - 1].Title</a></td>
                                </tr>
                            }
                        }
                    }
                </table>
            </div>
        </div>
    </div>
}
@{
    var user = Context.Session.Get<UserInfoDto>(SessionKey.UserInfo) ?? new UserInfoDto();
    await Html.RenderPartialAsync(user.IsAdmin ? "_MainContainer_Admin" : "_MainContainer", Model);
}
<script type="text/javascript">
    $('#bootstrap-touch-slider').bsTouchSlider();
</script>